gdk: Add gdk_device_get_timestamp
authorMatthias Clasen <mclasen@redhat.com>
Fri, 26 Mar 2021 02:39:15 +0000 (22:39 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 26 Mar 2021 14:30:33 +0000 (10:30 -0400)
Give each device a timestamp that reflects the last
user activity with that device, as reflected in the
events that are produced for this device.

gdk/gdkdevice.c
gdk/gdkdevice.h
gdk/gdkdeviceprivate.h
gdk/gdksurface.c

index 24a7d8b3b3f644127877fd4bebbac69407c2eb9d..ea0b78fb28cd8e26613433c133bd2a4144e79b00 100644 (file)
@@ -1381,3 +1381,31 @@ gdk_device_has_bidi_layouts (GdkDevice *device)
 
   return FALSE;
 }
+
+void
+gdk_device_set_timestamp (GdkDevice *device,
+                          guint32    timestamp)
+{
+  device->timestamp = timestamp;
+}
+
+/**
+ * gdk_device_get_timestamp:
+ * @device: a `GdkDevice`
+ *
+ * Returns the timestamp of the last activity for this device.
+ *
+ * In practice, this means the timestamp of the last event that was
+ * received from the OS for this device. (GTK may occasionally produce
+ * events for a device that are not received from the OS, and will not
+ * update the timestamp).
+ *
+ * Returns: the timestamp of the last activity for this device
+ *
+ * Since: 4.2
+ */
+guint32
+gdk_device_get_timestamp (GdkDevice *device)
+{
+  return device->timestamp;
+}
index 58d75199f80247a2776b7e0642f18631acba62bb..720347e95fd74aa562debe81270ff2236b6cf099 100644 (file)
@@ -117,6 +117,9 @@ GDK_AVAILABLE_IN_ALL
 GdkSurface *        gdk_device_get_surface_at_position  (GdkDevice *device,
                                                          double    *win_x,
                                                          double    *win_y);
+
+GDK_AVAILABLE_IN_4_2
+guint32             gdk_device_get_timestamp            (GdkDevice *device);
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_H__ */
index a4cfffc28bb4b43d86bc90693ac55a02ef61164f..8a2be66155d30b0a116d940674cfc98b1991cf75 100644 (file)
@@ -89,6 +89,8 @@ struct _GdkDevice
 
   GdkSeat *seat;
   GdkDeviceTool *last_tool;
+
+  guint32 timestamp;
 };
 
 struct _GdkDeviceClass
@@ -189,6 +191,9 @@ gboolean gdk_device_get_axis  (GdkDevice         *device,
 GdkAxisUse gdk_device_get_axis_use  (GdkDevice         *device,
                                      guint              index_);
 
+void gdk_device_set_timestamp (GdkDevice *device,
+                               guint32    timestamp);
+
 
 G_END_DECLS
 
index 6ad438093aa298afeaa9b8d5fc5fb855f949d460..c55a9a8042d60a3fe7861157cf76aaf4ad8dd339 100644 (file)
@@ -2248,13 +2248,18 @@ _gdk_windowing_got_event (GdkDisplay *display,
   GdkPointerSurfaceInfo *pointer_info = NULL;
   GdkDevice *device;
   GdkEventType type;
+  guint32 timestamp;
 
   _gdk_display_update_last_event (display, event);
 
   device = gdk_event_get_device (event);
+  timestamp = gdk_event_get_time (event);
 
   if (device)
     {
+      if (timestamp != GDK_CURRENT_TIME)
+        gdk_device_set_timestamp (device, timestamp);
+
       if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD &&
           gdk_device_get_source (device) != GDK_SOURCE_TABLET_PAD)
         {